package com.spider.silence.job;

import com.spider.silence.downloader.CRIOnlineForSiChuanDownloader;
import com.spider.silence.pool.CRIOnlineForSiChuanDownloaderPool;
import org.quartz.Job;
import org.quartz.JobExecutionContext;
import org.quartz.JobExecutionException;
import org.quartz.StatefulJob;

/**
 * Created by Linbo Hu on 2017/7/4.
 * 国际在线四川频道爬虫定时任务
 */
public class CRIOnlineForSiChuanJob implements StatefulJob {
    @Override
    public void execute(JobExecutionContext jobExecutionContext) throws JobExecutionException {
        CRIOnlineForSiChuanDownloaderPool downloaderPool = CRIOnlineForSiChuanDownloaderPool.getInstance();
        CRIOnlineForSiChuanDownloader downloader = null;
        try {
            downloader = downloaderPool.fetchDownLoader(1000);
            while (null == downloader) {
                System.out.println("第一次获取下载器失败, 定时器获取国际在线下载器");
                downloader = downloaderPool.fetchDownLoader(1000);
            }
            downloader.generateTask();
        } catch (InterruptedException e) {
            e.printStackTrace();
        } finally {
            if(downloader != null) {
                downloaderPool.releaseDownLoader(downloader);
            }
        }
    }
}
